//
//  FANStatusToolBar.swift
//  Weibo - Swift
//
//  Created by user on 16/4/20.
//  Copyright © 2016年 user. All rights reserved.
//

import UIKit

class FANStatusToolBar: UIView {

    
    override init(frame: CGRect) {
        
        super.init(frame: frame)
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI(){
        
        let retweetButton = getButton("转发", imageName: "timeline_icon_retweet")
        
        let commitButton = getButton("评论", imageName: "timeline_icon_comment")
        
        let likeButton = getButton("赞", imageName: "timeline_icon_unlike")
        
        addSubview(retweetButton)
        
        addSubview(commitButton)
        
        addSubview(likeButton)
        
        let sp1 = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
        let sp2 = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
        
        addSubview(sp1);addSubview(sp2)
        
        retweetButton.snp_makeConstraints { (make) -> Void in
            
            make.top.leading.bottom.equalTo(self)
            
            make.width.equalTo(commitButton)
        }
        
        commitButton.snp_makeConstraints { (make) -> Void in
            
//            make.top.bottom.equalTo(self)
            
            make.top.bottom.equalTo(self)
            
            make.leading.equalTo(retweetButton.snp_trailing)
            
            make.width.equalTo(likeButton)
        }
        
        likeButton.snp_makeConstraints { (make) -> Void in
            
            make.trailing.top.bottom.equalTo(self)
            
            make.leading.equalTo(commitButton.snp_trailing)
            
            make.width.equalTo(retweetButton)
        }
        
        sp1.snp_makeConstraints { (make) -> Void in
            
            make.centerX.equalTo(retweetButton.snp_trailing)
            
            make.centerY.equalTo(self)
        }
        
        sp2.snp_makeConstraints { (make) -> Void in
            
            make.centerX.equalTo(commitButton.snp_trailing)
            
            make.centerY.equalTo(self)
        }
        
    }
    
    private func getButton(title:String, imageName:String) ->UIButton{
        
        let button = UIButton(titleColor: UIColor.darkGrayColor(), fontSize: 14)
        
        button.setTitle(title, forState: .Normal)

        button.setImage(UIImage(named: imageName), forState: .Normal)
        
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: .Highlighted)
        
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: .Normal)
        
        return button
        
    }
    
    private var button:UIButton = {
        
        let button = UIButton(titleColor: UIColor.darkGrayColor(), fontSize: 14)

//        button.setTitle(<#T##title: String?##String?#>, forState: <#T##UIControlState#>)
        
//        button.setImage(<#T##image: UIImage?##UIImage?#>, forState: <#T##UIControlState#>)
        
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: .Highlighted)
        
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: .Normal)
        
        return button
    }()

}
